/*
 * @lc app=leetcode.cn id=17 lang=java
 *
 * [17] 电话号码的字母组合
 */

// @lc code=start
class Solution {

    private String[] map = new String[]{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    private StringBuffer sb = new StringBuffer();
    private List<String> res = new ArrayList<>();

    public List<String> letterCombinations(String digits) {
        if(digits.length() == 0 || digits == null) return res;
        backtrack(digits, 0);
        return res;


    }


    private void backtrack(String digits, int index){
        if(index == digits.length()){
            res.add(sb.toString());
            return;
        }
        String letters = map[digits.charAt(index) - '2'];
        for(int i = 0; i < letters.length(); i++){
            sb.append(letters.charAt(i));
            backtrack(digits, index + 1);
            sb.deleteCharAt(sb.length() - 1);
        }
    }
}
// @lc code=end

